package com.example.controller;

import com.example.utils.MinioUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;

/**
 * @Description : minio测试controller
 * @Author : ZYX
 * @Date : 2024/3/13 17:54
 * @Version : 1.0
 **/
@RestController
@RequestMapping("/minio")
@CrossOrigin
public class MinioController {

    @Autowired
    private MinioUtil minioUtil;


    /**
     * 上传文件
     */
    @PostMapping(value = "/upload")
    public String upload(@RequestParam(name = "file") MultipartFile multipartFile,String fileName) throws Exception {
        minioUtil.upload(multipartFile,fileName);
        return "0";
    }

    /**
     * 下载文件
     */
    @GetMapping(value = "/download")
    public ResponseEntity<byte[]> download(@RequestParam(name = "fileName") String fileName) {

        return minioUtil.download(fileName);
    }

    @GetMapping("/getUrl")
    public HashMap<String, Object> getFileUrl(@RequestParam("fileName") String fileName){
        HashMap<String, Object> map = new HashMap<>();
        map.put("fileUrl",minioUtil.getFileUrl(fileName));
        return map;
    }

}
